package com.wenjie.springbootbugdetection.service.impl;

import com.wenjie.springbootbugdetection.mapper.BugMapper;
import com.wenjie.springbootbugdetection.model.Bug;
import com.wenjie.springbootbugdetection.service.BugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Yang wenjie
 * @date 2021/7/6 14:37
 * Nice to Meet you!
 */
@Service
public class BugServiceImpl implements BugService {
    @Autowired
    private BugMapper bugMapper;
    @Override
    public Bug queryBug(Integer bugId) {
        return bugMapper.selectByPrimaryKey(bugId);
    }

    @Override
    public List<Bug> selectAllBugs() {
        return bugMapper.selectAllBugs();
    }

    @Override
    public int delectABug(Integer bugId) {
        return bugMapper.deleteByPrimaryKey(bugId);
    }

    @Override
    public int checkedABug(Integer bugId, Integer testManagerId) {
        Bug bug = queryBug(bugId);
//        bug.setStatusId(3);
        bug.setTestManagerId(testManagerId);
        return bugMapper.updateByPrimaryKey(bug);
    }

    @Override
    public int checkedABugFalse(Integer bugId, Integer testManagerId) {
        Bug bug = queryBug(bugId);
        bug.setStatusId(2);
        bug.setTestManagerId(testManagerId);
        return bugMapper.updateByPrimaryKey(bug);
    }

    @Override
    public int solvedABug(Integer bugId, Integer developmentId) {
        Bug bug = queryBug(bugId);
        bug.setStatusId(4);
        bug.setDevelopmentId(developmentId);
        bug.setSolveTime(new Date());
        return bugMapper.updateByPrimaryKey(bug);
    }

    @Override
    public int insertABug(Bug bug) {
        return bugMapper.insert(bug);
    }

    @Override
    public int updateABug(Bug bug) {
        return bugMapper.updateByPrimaryKeySelective(bug);
    }
}
